﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ebc.componentbinder.Helpers;

namespace ebc.componentbinder.tests
{
    [TestFixture]
    public class test_PairUpPins
    {
        [Test]
        public void Connect_1_event_to_n_handlers()
        {
            var c = new C();
            var s = new S();
            var t = new T();

            var cop = new OutputPin(c, typeof (C).GetEvent("OnX"));
            var sip = new InputPin(s, typeof (S).GetMethod("ProcessX"));
            var tip = new InputPin(t, typeof (T).GetMethod("ProcessX"));

            var expectedPairs = new List<OutputInputPinPair>
                                    {
                                        new OutputInputPinPair {Out=cop, In=sip},
                                        new OutputInputPinPair {Out=cop, In=tip}
                                    };

            var pairsFound = new List<OutputInputPinPair>();
            ComponentBinder.PairUpPins(new object[] {c, s, t})
                .ForAll(pairsFound.Add);

            Assert.That(pairsFound, Is.EqualTo(expectedPairs));
        }
    }
}
